package org.weso.desempleo.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import org.weso.desempleo.model.Charger;
import org.weso.desempleo.services.to.ListConcejoStatsTO;
import org.weso.desempleo.services.to.ListEdadesStatsTO;
import org.weso.desempleo.services.to.ListGeneroStatsTO;
import org.weso.desempleo.services.to.ListMunicipalityStatsTO;
import org.weso.desempleo.services.to.ListSectoresStatsTO;

@Path("/paro")
public class ParoServiceRest {

		
    @GET
    @Path("concejos")
    @Produces({/*"text/plain", "application/xml",*/ "application/json"})
    public ListConcejoStatsTO concejos(@QueryParam("lang") String lang){
        try{
        	Charger c = Charger.getInstance(Charger.CHARGER_CONCEJO);
        	ListConcejoStatsTO concejos = (ListConcejoStatsTO)
        			c.obtain(lang, null, null, null, null);
        	return concejos;
        }catch(Exception e){
        	System.err.println(e.getLocalizedMessage());
        	throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }
    }
    
    @GET
    @Path("generos")
    @Produces({/*"text/plain", "application/xml", */"application/json"})
    public ListGeneroStatsTO generos(@QueryParam("lang") String lang, 
    		@QueryParam("sexo") String genero, 
    		@QueryParam("month") String month,
    		@QueryParam("anyo") String anyo, 
    		@QueryParam("langAnt") String langAnt){
    	try {
			Charger c = Charger.getInstance(Charger.CHARGER_GENERO);
			ListGeneroStatsTO generos = (ListGeneroStatsTO)c.obtain(lang, anyo,
					month, genero, langAnt);
			return generos;
		} catch (Exception e) {
			e.printStackTrace();
			throw new WebApplicationException(Response.Status.BAD_REQUEST);
		}
    }
    
    @GET
    @Path("edades")
    @Produces({/*"text/plain", "application/xml",*/ "application/json"})
    public ListEdadesStatsTO edades(@QueryParam("year") String year, 
    		@QueryParam("edad") String edad, @QueryParam("month") String month, 
    		@QueryParam("lang") String lang, 
    		@QueryParam("anyo") String anyo,
    		@QueryParam("langAnt") String langAnt){
    	Charger c;
		try {
			c = Charger.getInstance(Charger.CHARGER_EDAD);
			ListEdadesStatsTO edades = (ListEdadesStatsTO)
			    	c.obtain(lang, anyo, month, edad, langAnt);
			return edades;
		} catch (Exception e) {
			e.printStackTrace();
			throw new WebApplicationException(Response.Status.BAD_REQUEST);
		}
    }
    
    
	@GET
    @Path("sectores")
    @Produces({/*"text/plain", "application/xml",*/ "application/json"})
    public ListSectoresStatsTO sectores(@QueryParam("anyo") String anyo, 
    		@QueryParam("month") String month, 
    		@QueryParam("sector") String sector,
    		@QueryParam("lang") String lang, 
    		@QueryParam("langAnt") String langAnt){
		try {
			Charger c = Charger.getInstance(Charger.CHARGER_SECTOR);
			return (ListSectoresStatsTO)c.obtain(lang, anyo, month, sector, 
					langAnt);
		} catch (Exception e) {
			System.err.println(e.getMessage());
			throw new WebApplicationException(Response.Status.BAD_REQUEST);
		}
    }
	
	@GET
    @Path("municipios")
    @Produces({/*"application/xml",*/ "application/json"})
    public ListMunicipalityStatsTO municipios(@QueryParam("lang") String lang){
		try {
			Charger c = Charger.getInstance(Charger.CHARGER_MUNICIPIO);
			ListMunicipalityStatsTO municipios = (ListMunicipalityStatsTO)
					c.obtain(lang, null, null, null, null);
			return municipios;
		} catch (Exception e) {
			System.err.println(e.getMessage());
			throw new WebApplicationException(Response.Status.BAD_REQUEST);
		}
    }
}
